<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/css/my_sty.css">
    <style>
        body {
            /* url() 为自定义鼠标样式路径 */
            cursor: url(../static/image/pointer.png),auto;
        }
    </style>
</head>
<body >
    <div id="container" class="shadow p-3 mb-5 bg-white rounded">
        <div id="title">
            <h1 style="text-align: center; margin-top:0rem; margin-bottom: 1rem;">注册</h1>
        </div>

        <form>
            <!-- 文本框 -->
            <div id="body_middle">
                <div class="row">
                  <div class="col">
                      <center>
                          <input type="text" class="form-control" id="register_username" name="register_username" placeholder="用户名/手机号/邮箱" style="width: 50%; text-align: center;">
                      </center>
                  </div>
                </div>
                <div class="row">
                    <div class="col">
                        <center>
                            <input type="password" class="form-control" id="register_password" name="register_password" placeholder="请输入密码" style="width: 50%; text-align: center">
                        </center>
                    </div>
                </div>
                <div class="row">
                    <div class="col">
                        <center>
                            <input type="password" class="form-control" id="register_confirm_password" name="register_confirm_password" placeholder="请确认密码" style="width: 50%; text-align: center">
                        </center>
                    </div>
                </div>
            </div>
            <br>
                <!-- 按钮组件 -->
                <div style="text-align:right">
                    <center></center>
                    <button type="button" id="submit"  class="btn btn-outline-primary" style="width: 5rem;">提交</button> 
                    <button type="button" id="reset" name="reset" class="btn btn-outline-primary" style="width: 5rem;">重置</button> 
                </div>
            </div>
        </form>
    </div>
    
    <script src="../static/js/jquery-3.5.1.min.js"></script>
    <script src="../static/js/bootstrap.min.js"></script>
    <script src="../static/js/register_btn.js"></script>
    <script src="../static/js/register_input_focus.js"></script>
    <!-- <script src="../static/js/a.js"></script>
    <script src="../static/js/b.js"></script> -->

    <script>
         function jump() {
            // 获取表单数据
            let uid = $('#username').val();
            let pwd = $('#password').val();
            let confirmpwd = $('#confirmpassword').val();

            // 判断用户名、密码是否为空，为空则提示；不为空则向服务器提交
            if (uid.length > 0 && pwd.length > 0 && pwd === confirmpwd) {
                axios({
                    method: 'post',
                    url: '/registerDone',
                    data: $('#registerForm').serialize(),
                }).then(function (res) {
                    // axios工具下，服务器真正返回的数据在返回对象的data中
                    res = res.data;
                    if (res.code === 200) {
                        window.location.href = '/login';
                    } else {
                        alert_fn(res.msg);
                        console.log(res.msg);
                    }
                }).catch((err) => {
                    alert_fn(err);
                    console.log(err);
                });
            } else {
                alert_fn('用户名、密码不能为空，并且两次密码应该一致');
            }
        }

        // 包装了显示（以及自动隐藏）消息警告的动作
        function alert_fn(msg){
            $('#msgId').text(msg);
            $('.alert').removeClass('invisible');
            setTimeout(() => {
                $('.alert').addClass('invisible');
            }, 3000);
        }
    </script>

</body>
</html>